class AppObject {
  isLoaded = false;
}

const SupportRobots = {
  UR5:{
    dof:6,
  }
}

// 协作机器人通用类
class Cobots extends AppObject{
  id="";
  dof=-1;
  joints=[];
  robot=null;

  jointSpeed = Math.PI / 180;

  init( id ) {
    const robot = SupportRobots[id];
    if( robot ) {
      this.id = id;
      this.dof = robot.dof;
    }
  }

  setRobot( robot ) {
    this.robot = robot;
    this.joints = [];
    for( let jointName in robot.joints ) {
      const joint = robot.joints[jointName];
      if( joint._jointType === 'fixed' ) continue;
      
      this.joints.push(joint);
    }
    this.isLoaded = true;
  }

  reset() {
    this.id = "";
    this.dof = -1;
    this.joints = [];
    this.robot = null;
    this.isLoaded = false;
  }

  jointValueIncrease( jointName ) {
    const joint = this.robot.joints[jointName];
    if( joint ) {
      joint.setJointValue(joint.angle + 1);
    }
  }

  jointValueDecrease( jointName ) {
    const joint = this.robot.joints[jointName];
    if( joint ) {
      joint.setJointValue(joint.angle - 1);
    }    
  }

}


export {
  Cobots,
}